package cn.itcast.travel.web.v0;

import cn.itcast.travel.service.UserService;
import cn.itcast.travel.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
 * 邮件的激活
 * @author
 * */
//@WebServlet("/activeUserServlet")
public class ActiveUserServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取请求的激活码
        String code = request.getParameter("code");
        if (code==null){
            return;
        }
        UserService userService = new UserServiceImpl();
        boolean flag=userService.active(code);
        String msg=null;
        if (flag){
            //激活成功
            msg="激活成功，请<a href='http://localhost/login.html'>登录</a>";
        }else{
            //激活失败
            msg="激活失败！请联系管理员";
        }
        response.setContentType("text/html;charset=utf-8");
        response.getWriter().write(msg);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }
}
